#include<bits/stdc++.h>
using namespace std;

int a[10];

int main()
{
	int n;
	while(cin>>n && n)
	{
		for(int i = 1;i <= n;i++)
			a[i] = i;
		do
		{
			for(int i = 1;i < n;i++)
				cout<<a[i]<<" ";
			cout<<a[n]<<endl;
		}while(next_permutation(a+1, a+n+1));
	}
	return 0;
}

